function parse(e) {
	for(var t = e, o = new RegExp(/&lt;e (.*?)\/&gt;/g), i = !0; i;) {
		var n = o.exec(e);
		if(n) {
			var a = n[1].split(" ");
			if('type="hashtag"' == a[0] && a.length > 4) {
				var r = new RegExp(/.*title="(.*)".*/i),
					s = r.exec(n[1]);
				a[2] = 'title="' + s[1] + '"', a = a.slice(0, 3)
			}
			var c = {};
			a.forEach(function(e) {
				if(e.length > 0) {
					var t = e.split("="),
						o = t[0],
						i = t[1].split('"')[1];
					c[o] = i
				}
			});
			var l = n[0],
				d = "";
			switch(c.type) {
				case "@":
				case "mention":
					d = this.parseMention(c);
					break;
				case "web":
					d = this.parseHref(c);
					break;
				case "hashtag":
					d = this.parseTag(c);
					break;
				default:
					d = this.parseStrangeType(c)
			}
			t = t.replace(l, d)
		} else t = t.replace(/^\&|\&(amp;)/g, "&amp;"), i = !1
	}
	return t
}

function parseMention(e) {
	if("mention" == e.type) {
		var t = (e.uid, decodeURIComponent(e.title));
		t = t.replace(/</g, "&lt;").replace(/>/g, "&gt;");
		var o = t;
		return o
	}
	var t = (e.uid, decodeURIComponent(e.name));
	t = t.replace(/&(?!g|l)/g, "&amp;");
	var o = t;
	return o
}

function parseHref(e) {
	var t = (e.uid, decodeURIComponent(e.title));
	t = t.replace(/\+/g, " ");
	var o = decodeURIComponent(e.href),
		i = decodeURIComponent(e.cache);
	return "undefined" != i ? '<a href="' + i + '" target="_blank">链接：</a><a href="' + o + '" title="' + t + '" target="_blank" style="color: #567895;">' + t + "</a>" : '<a href="' + o + '" title="' + t + '" target="_blank">链接：' + t + "</a>"
}

function parseTag(e) {
	var t = e.hid,
		o = decodeURIComponent(e.title);
	return o = o.replace(/</g, "&lt;").replace(/>/g, "&gt;"), o = o.replace(/&(?!g|l)/g, "&amp;"), '<span class="hashtag" hid="' + t + '">' + o + "</span>"
}

function parseStrangeType(e) {
	return decodeURIComponent(e.title)
}

function GetQueryString(e) {
	var t = new RegExp("(^|&)" + e + "=([^&]*)(&|$)"),
		o = window.location.search.substr(1).match(t);
	return null != o ? unescape(o[2]) : null
}

function isPC() {
	for(var e = navigator.userAgent, t = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPod", "iPad"], o = !0, i = 0; i < t.length; i++)
		if(e.indexOf(t[i]) > 0) {
			o = !1;
			break
		}
	return o
}

function allCookies() {
	var e = Cookies.get("m_wx_name"),
		t = Cookies.get("m_user_id"),
		o = Cookies.get("m_user_avatar_url");
	e && Cookies.set("m_wx_name", e, {
		expires: 5
	}), t && Cookies.set("m_user_id", t, {
		expires: 5
	}), o && Cookies.set("m_user_avatar_url", o, {
		expires: 5
	})
}
var APPID = "wx06e5eac480a6d984",
	URL = "https://wx.xiaomiquan.com/mweb/",
	API_URL = "https://api.xiaomiquan.com/v1.6/",
	WAPI_URL = "https://wapi.xiaomiquan.com/v1.6/",
	APP_OPEN_ID = "wx958aa81d89e22ca4",
	toastTime = null,
	displayTime = null,
	savedBgColor = null,
	codeMap = {
		600: "网络超时",
		16903: "账户余额不足",
		16905: "提现过于频繁",
		16908: "您今日的提现次数超过限制",
		16909: "短时间内提现过于频繁，请稍后重试",
		50001: "请求失败(50001)",
		50003: "请求失败(50003)",
		50101: "圈子已被删除",
		50202: "圈主不能成为嘉宾",
		50203: "您要加入的圈子不存在",
		50204: "您已经是嘉宾",
		50205: "该链接已失效",
		50206: "已超过圈子嘉宾数量限制",
		50501: "主题已被删除"
	},
	Public = {
		init: function() {
			this.getSize(), this.setBorderWidth(), $(".js_goto_my").on("click", function() {
				window.location.href = "../myhome/myhome.html?d=" + (new Date).getTime().toString().substr(-8)
			}), $(".js_goto_group").on("click", function() {
				window.location.href = "../grouplist/grouplist.html?d=" + (new Date).getTime().toString().substr(-8)
			}), $(".err_refresh").on("click", function() {
				urlReload()
			})
		},
		getSize: function() {
			$.fn.fontFlex = function(e, t, o) {
				var i = this;
				$(window).resize(function() {
					var n = window.innerWidth / o;
					n < e && (n = e), n > t && (n = t), isPC() ? (n = 17, savedBgColor = $("body").css("background-color"), $("body").css("background-color", "#e5e5e5")) : savedBgColor && $("body").css("background-color", savedBgColor), i.css("font-size", n + "px")
				}).trigger("resize")
			}, $("html").fontFlex(10, 20, 50)
		},
		setBorderWidth: function() {
			if(/iP(hone|od|ad)/.test(navigator.userAgent)) {
				var e = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
				if(parseInt(e[1], 10) >= 8) {
					$($("head")[0]).append('<link rel="stylesheet" href="../../css/border.css"/>')
				}
			}
		},
		loadAjaxData: function(e, t, o, i, n, a, r, s, c, l) {
			n = n || "get", l = !l, a = a || "json", allCookies();
			var d = Cookies.get("m_access_token");
			d ? Cookies.set("m_access_token", d, {
				expires: 5
			}) : d = "", "object" == typeof t && l && (t = JSON.stringify(t)), $.ajax({
				type: n,
				url: e,
				data: t,
				async: r,
				cache: c,
				processData: s,
				contentType: !1,
				dataType: a,
				timeout: 2e4,
				success: function(e) {
					401 == e.code || 16904 == e.code ? (Cookies.remove("m_access_token"), Public.wxlogin()) : o && o(e)
				},
				error: function(e, t) {
					i && i(e, t)
				},
				headers: {
					Authorization: d,
					"X-Request-Id": getXRequestId()
				}
			})
		},
		showToast: function(e, t) {
			t || (t = 1e3), null != toastTime && (clearTimeout(toastTime), clearTimeout(displayTime)), 0 == $("#toastId").get().length && $("body").append('<div id="toastId" class="toasttj" style="z-index:1003;font-size: 1.5rem;position: fixed;bottom:50%;opacity:0;height: 24px;width:100%;display: none;transition: opacity 1s ease-out;"></div>'), $("#toastId").css("display", "block"), $("#toastId").css("opacity", 1), $("#toastId").html('<div style="color:#fff;background: rgba(0, 0, 0, 0.6);border-radius: 2px;width:18rem;padding: .5rem;text-align: center;margin: 0 auto;">' + e + "</div>"), toastTime = setTimeout(function() {
				$("#toastId").css("opacity", 0), displayTime = setTimeout(function() {
					$("#toastId").css("display", "none")
				}, 1e3)
			}, t)
		},
		showToastByCode: function(e, t) {
			if(t) return Public.showToast(t, 2e3), !0;
			if(codeMap[e]) {
				var o = codeMap[e];
				return Public.showToast(o, 2e3), !0
			}
			return Public.showToast("错误码： " + e, 2e3), !1
		},
		showErrorPage: function(e) {
			$(".main_loading").remove(), 600 == e ? $(".network_error").show() : ($(".api_err_code").html(e), $(".api_error").show())
		},
		showAlwaystoast: function() {
			$("body").append("<div class='hint-form close_normal'><div class='hint-body'><p class='conform-close' onclick='riskClose()'></p><p class='conform-txt'>该圈可能包含违反社区规范<br/>的内容，请谨慎加入</p><a class='join-aa b-r-4' onclick='riskClose()'>知道了</a></div></div>"), $(".code-bg").show()
		},
		wxlogin: function() {
			Cookies.set("m_target", window.location.href);
			var e = URL + "views/wxlogin/login.html";
			window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + APPID + "&redirect_uri=" + encodeURIComponent(e) + "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect"
		},
		isWeiXin: function() {
			return "micromessenger" == window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i)
		},
		isLogined: function() {
			return !!Cookies.get("m_access_token")
		},
		setTitle: function(e) {
			if(Public.isWeiXin()) {
				var t = $("body");
				document.title = e;
				var o = $("<iframe style='display:none;' src='/favicon.ico'></iframe>");
				o.on("load", function() {
					setTimeout(function() {
						o.off("load").remove()
					}, 0)
				}).appendTo(t)
			} else document.title = e
		},
		showJoinHint: function(e, t) {
			var o = "'" + e + "'",
				i = "";
			i = "loginAllow" == e ? "<div class='hint-form close_normal'><div class='hint-body'><p class='conform-close' onclick='Public.close()'></p><p class='conform-txt'>圈内成员才能点赞和评论，<br/>加入圈子查看更多精彩内容</p><a onclick=Public.postApplication(" + o + "," + t + ") class='join-aa b-r-4'>加入圈子</a></div></div>" : "<div class='hint-form close_normal'><div class='hint-body'><p class='conform-close' onclick='Public.close()'></p><p class='conform-txt'>圈内成员才能点赞和评论，<br/>加入圈子查看更多精彩内容</p><a onclick=Public.postApplication(" + o + "," + t + ") class='join-aa b-r-4'>申请加入圈子</a></div></div>", $("body").append(i), $(".code-bg").show()
		},
		confirmLogin: function(e) {
			if("unLoginAllow" == e && Public.wxlogin(), "loginAllow" == e) {
				var t = "'" + e + "'";
				$(".hint-form").remove();
				var o = "<div class='hint-form close_update b-r-4'><div class='hint-body  b-r-4'><p class='conform-close' onclick=Public.close(" + t + ")></p><p class='conform-txt'>圈内成员才能点赞和评论，<br/>加入圈子查看更多精彩内容</p><p class='next-txt'>已成功加入圈子</p></div></div>";
				$("body").append(o), $(".code-bg").show()
			}
			if("loginApply" == e) {
				var t = "'" + e + "'";
				$(".hint-form").remove();
				var o = "<div class='hint-form close_update b-r-4'><div class='hint-body  b-r-4'><p class='conform-close' onclick=Public.close(" + t + ")></p><p class='conform-txt'>圈内成员才能点赞和评论，<br/>加入圈子查看更多精彩内容</p><p class='next-txt'>申请已发送，等待管理员审核</p></div></div>";
				$("body").append(o), $(".code-bg").show()
			}
		},
		close: function(e) {
			event.cancelBubble = !0, $(".hint-form").css("display", "none"), $(".code-bg").hide(), "loginApply" != e && "loginAllow" != e || urlReload()
		},
		postApplication: function(e, t) {
			var o = API_URL + "groups/" + t + "/examinations",
				i = function(t) {
					t.succeeded ? "allowed" == t.resp_data.status ? ($(".hint-form").remove(), Public.confirmLogin(e)) : "examining" == t.resp_data.status && Public.confirmLogin(e) : Public.showToastByCode(t.code)
				},
				n = function() {
					Public.showToastByCode(600)
				};
			Public.loadAjaxData(o, "", i, n, "post")
		},
		bindTouchHover: function(e, t) {
			$("body").on("touchstart", e, function(e) {
				$(this).addClass(t)
			}), $("body").on("touchmove", e, function(e) {
				$(this).hasClass(t) && $(this).removeClass(t)
			}), $("body").on("touchend", e, function(e) {
				$(this).hasClass(t) && $(this).removeClass(t)
			}), $("body").on("touchcancel", e, function(e) {
				$(this).hasClass(t) && $(this).removeClass(t)
			})
		},
		promptBox: function(e, t) {
			var o = ' <div class="code-bg" style="display: block;"></div><div class="prompt_box b-r-4"><div class="prom_div"><p class="prom_p">' + e + '</p><div class="prom_buttons"><a class="prom_cancel" onclick="Public.closeprom()">取消</a><a class="prom_ok ' + t + '">确定</a></div></div></div>';
			$("body").append(o)
		},
		closeprom: function() {
			$(".code-bg,.prompt_box").remove()
		}
	};
$(function() {
	Public.init()
}), document.onreadystatechange = function() {
	"complete" == document.readyState && $("body").show()
}, template.helper("parseBg", function(e, t) {
	if(e.indexOf("builtin://") != -1) {
		var o = e.split("//"),
			i = o[1];
		e = URL + "images/group_bg/" + i + ".png"
	}
	return "square" == t && (e = URL + "images/group_bg/square_group.png"), e
}), template.helper("formatTime", function(e, t) {
	if(e) {
		e = e.substring(0, e.length - 5);
		var o = new Date(e),
			i = o.getFullYear(),
			n = o.getMonth() + 1,
			a = o.getDate(),
			r = i + "." + n + "." + a;
		"after" == t && (r = 29 == a ? i + 1 + "." + n + ".28" : i + 1 + "." + n + "." + a)
	}
	return r
}), template.helper("parseTime", function(e) {
	var t = moment(e),
		o = moment(),
		i = parseInt(o.format("X")) - parseInt(t.format("X")),
		n = parseInt(t.format("YYYYMMDD")),
		a = parseInt(o.format("YYYYMMDD")),
		r = "";
	return n == a - 1 ? r = "昨天 " + t.format("HH:mm") : n == a - 2 ? r = "前天 " + t.format("HH:mm") : n < a ? r = t.format("YYYY/M/D") : i < 60 ? r = "刚刚" : (t.locale("zh-cn"), r = t.fromNow()), r
}), template.helper("parseText", function(e, t) {
	if(e) {
		var o = e;
		o = o.replace(/</g, "&lt;").replace(/>/g, "&gt;");
		try {
			o = parse(o)
		} catch(e) {
			o = ""
		}
		t = o
	}
	return t
}), template.helper("fileIcon", function(e, t) {
	var o = e.split(".");
	return o[o.length - 1] + "_ext"
}), template.helper("parseLength", function(e) {
	return Math.floor(e / 60) + ":" + (e % 60 / 100).toFixed(2).slice(-2)
});
var getXRequestId = function() {
		return function() {
			for(var e = "", t = 1; t <= 32; t++) {
				e += Math.floor(16 * Math.random()).toString(16), 8 != t && 12 != t && 16 != t && 20 != t || (e += "-")
			}
			return e
		}()
	},
	resizeImg = function(e) {
		var t = $(e.target),
			o = t.css("width");
		o = parseInt(o.replace("px", ""));
		var i = $("html").css("font-size");
		i = parseInt(i.replace("px", "")), o /= i;
		var n = e.target.width,
			a = e.target.height,
			r = n / a;
		if(n > a) {
			var s = o * r;
			t.css("height", o.toFixed(2) + "rem"), t.css("width", s.toFixed(2) + "rem"), t.css("left", "-" + ((s - o) / 2).toFixed(2) + "rem")
		} else if(n < a) {
			var c = o / r;
			t.css("height", c.toFixed(2) + "rem"), t.css("width", o.toFixed(2) + "rem"), t.css("top", "-" + ((c - o) / 2).toFixed(2) + "rem")
		}
		t.css("z-index", "1")
	},
	urlReload = function() {
		var e = GetQueryString("d"),
			t = window.location.href;
		e ? window.location.href = t.replace("d=" + e, "d=" + (new Date).getTime().toString().substr(-8)) : t.indexOf("?") != -1 ? window.location.href = t + "&d=" + (new Date).getTime().toString().substr(-8) : window.location.href = t + "?d=" + (new Date).getTime().toString().substr(-8)
	},
	open_xmq = function(e, t, o) {
		function i() {
			WeixinJSBridge.invoke("getInstallState", {
				packageName: "com.unnoo.quan"
			}, function(i) {
				if("get_install_state:no" == i.err_msg) window.location.href = "http://t.72h.io/xmq/";
				else {
					if("guest" == e) var a = "action=open";
					else var a = "action=view_topic&topic_uid=" + o + "&group_uid=" + t + "&user_uid=" + n;
					WeixinJSBridge.invoke("launch3rdApp", {
						appID: "wx958aa81d89e22ca4",
						extInfo: a
					}, function(e) {}), WeixinJSBridge.call("closeWindow")
				}
			})
		}
		var n = Cookies.get("m_user_id") || "";
		if(Public.isWeiXin) {
			var a = navigator.userAgent.toLowerCase();
			/iphone|ipad|ipod/.test(a) ? (window.location.href = "guest" == e ? "wx958aa81d89e22ca4://extract?action=open" : "wx958aa81d89e22ca4://extract?action=view_topic&topic_uid=" + o + "&group_uid=" + t + "&user_uid=" + n, setTimeout(function() {
				window.location.href = "http://t.72h.io/xmq/"
			}, 2e3)) : /android/.test(a) && ("object" == typeof WeixinJSBridge && "function" == typeof WeixinJSBridge.invoke ? i() : document.addEventListener && document.addEventListener("WeixinJSBridgeReady", i, !1))
		} else window.location.href = "http://t.72h.io/xmq/"
	};
template.helper("defineWidth", function(e, t, o) {
	if(1 == o.length) {
		if(e > t) {
			e = e / t * (t < 150 ? 75 : 150), e = e > 200 ? 200 : e
		} else e = t > e ? e < 150 ? 75 : 150 : e > 200 ? 200 : e < 150 ? 75 : e;
		return e + "px"
	}
	return "90px"
}), template.helper("defineHeight", function(e, t, o) {
	if(1 == o.length) {
		if(t > e) e = e < 150 ? 75 : 150;
		else if(e > t) {
			var i = t < 150 ? 75 : 150;
			e = e / t * i, e = e > 200 ? 200 : e
		} else e = e > 200 ? 200 : e < 150 ? 75 : e;
		return e + "px"
	}
	return "90px"
}), template.helper("imgWidth", function(e, t, o) {
	if(1 == o.length)
		if(e > t) {
			var i = t < 150 ? 75 : 150;
			e = e / t * i
		} else e = t > e ? e < 150 ? 75 : 150 : e > 200 ? 200 : e < 150 ? 75 : e;
	else e = e > t ? e / t * 90 : 90;
	return e + "px"
}), template.helper("imgHeight", function(e, t, o) {
	if(1 == o.length)
		if(t > e) e = e < 150 ? 75 : 150;
		else if(e > t) {
		var i = t < 150 ? 75 : 150;
		e = e / t * i
	} else e = e > 200 ? 200 : e < 150 ? 75 : e;
	else e = e > t ? e / t * 90 : 90;
	return e + "px"
}), template.helper("imgMarginTop", function(e, t, o) {
	return "0px"
}), template.helper("imgMarginLeft", function(e, t, o) {
	var i = 0;
	if(1 == o.length) {
		if(e < t) {
			var n = e < 150 ? 75 : 150;
			t = t / e * n, i = t > 200 ? -(t - 200) / 2 : 0
		}
	} else e < t && (t = t / e * 90, i = -(t - 90) / 2);
	return i + "px"
});